import axios from "../../http/axios.js";
import {
  apiGetUserServiceAddress
} from "../../http/server.js";

export function getUserServiceAddress() {
  return new Promise((resolve, reject) => {
    axios({
      url: apiGetUserServiceAddress,
      data: {
        userId: wx.getStorageSync("userInfo").userId
      }
    }).then(res => {
      let list = [];
      res.forEach((item, index) => {
        let name = "",
          sex = "";
        if (Number(item.type) === 1) {
          name = item.provinceName === item.cityName ? `${item.provinceName}${item.countyName}` : `${item.provinceName}${item.cityName}${item.countyName}`;
          sex = item.detailedAddress;
        } else {
          name = item.hospital;
          sex = `${item.inpatientArea}病区${item.bed}床`;
        }
        list.push({
          name,
          sex,
          type: item.type,
          addressId: item.addressId
        })
      });
      resolve(list);
    }).catch(fail => {
      reject(fail)
    })
  })
}